package com.netnovelstore.typeHandler;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.netnovelstore.pojo.Message;
import org.apache.commons.lang.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class ListMessageTypeHandler extends AbstractObjectTypeHandler<List<Message>> {
    @Override
    public List<Message> getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String data = rs.getString(columnName);
        return StringUtils.isBlank(data) ? null : JSON.parseObject(data, new TypeReference<List<Message>>() {
        });

    }

    @Override
    public List<Message> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String data = rs.getString(columnIndex);
        return StringUtils.isBlank(data) ? null : JSON.parseObject(data, new TypeReference<List<Message>>() {
        });

    }

    @Override
    public List<Message> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String data = cs.getString(columnIndex);
        return StringUtils.isBlank(data) ? null : JSON.parseObject(data, new TypeReference<List<Message>>() {
        });

    }
}
